package controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import beans.UserPwdFormBean;

public class saveServlet extends HttpServlet{

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
       
        HttpSession s = request.getSession(true);
        
		UserPwdFormBean upfb = (UserPwdFormBean)s.getValue("UPFB");	
		
		upfb.setId(save(upfb));
        
        String foreward;
        String save = request.getParameter("submit");
        
        if(save != null)
        {
        	foreward = "/quittung.jsp";
        }
        else
        {
        	foreward = "/eingabe.jsp";
        }
        
        RequestDispatcher rd;
        rd = request.getRequestDispatcher(foreward);
        rd.forward(request, response);
        
	}
	
	private int save(UserPwdFormBean upfb) {
		return (int)(Math.random() * 1000);
	}
}
